/**
 * 
 */
package cyclopean.world.actor;

import cyclopean.world.zone.Position;


// TODO Javadoc
/**
 * 
 *
 * @author Jaco van der Westhuizen
 */
abstract public class Walker extends Pawn
{
    private static final float MAX_PITCH = (float)(Math.PI * 0.45);
    private static final float MIN_PITCH = -MAX_PITCH;

    protected final float speed;

    protected float heading;
	protected float pitch;
	protected float fx;
	protected float fy;

	/**
     * @param pos Its starting position.
     * @param mobility The reciprocal of its mass. 
	 * @param speed The force to apply on itself when walking.
     */
    protected Walker(Position pos, float mobility, float speed)
    {
	    super(pos, mobility);
	 
	    this.speed = speed;

	    // TODO Starting heading and pitch
	    turn(0, 0, 0);
    }

	/* (non-Javadoc)
	 * @see cyclopean.world.Pawn#lookAt(cyclopean.world.Position)
	 */
	@Override
	public void lookAt(Position pos)
	{
		// TODO Auto-generated method stub
	}

	/* (non-Javadoc)
	 * @see cyclopean.world.Pawn#move(float, float, float)
	 */
	@Override
	public void move(float forward, float right, float up)
	{
		applyBodyForce(speed * (forward * fx + right * fy), speed * (forward * fy - right * fx), up);
	}

	/* (non-Javadoc)
	 * @see cyclopean.world.Pawn#turn(float, float, float)
	 */
	@Override
	public void turn(float right, float up, float spin)
	{
		heading -= right;
		pitch   += up;
		fx = (float)Math.cos(heading);
        fy = (float)Math.sin(heading);

		if (pitch > MAX_PITCH)
		    pitch = MAX_PITCH;
        
        if (pitch < MIN_PITCH)
            pitch = MIN_PITCH;

	    pos.setAngles(this.heading, this.pitch);
	}
}
